package com.navinfo.platform.trip.common.arithmetic;

import com.navinfo.platform.trip.common.arithmetic.annotation.Arithmetic;
import com.navinfo.platform.trip.common.arithmetic.data.CommonData;
import com.navinfo.platform.trip.common.arithmetic.data.OuterEventData;
import com.navinfo.platform.trip.common.arithmetic.data.OuterStatisticData;
import com.navinfo.platform.trip.common.arithmetic.manager.EventConvert;
import com.navinfo.platform.trip.common.arithmetic.var.VarCarIgnite;
import com.navinfo.platform.trip.common.arithmetic.enums.EventType;
import com.navinfo.platform.trip.common.arithmetic.manager.AbstractArithmetic;
import com.navinfo.platform.trip.common.config.ConfigMap;

/**
 * 车辆点火算法.<br>
 * 输出：事件<br/>
 */
@Arithmetic(name = "车辆点火算法")
public class CarIgnite extends AbstractArithmetic<VarCarIgnite> {
    /**
     * 点火算法转速阀值
     */
    private int rotationThreshold = ConfigMap.getInteger("Ignite_Rotation_Threshold");

    @Override
    public void calculate() {
        logger.debug("进入点火算法.");
        VarCarIgnite var = getObj();
        CommonData commonData = getCommonData();

        Integer preRotation = var.getPreRotation();
        int curRotation = commonData.getRotation();

        if (commonData.isTripFirstNode() || (preRotation != null && preRotation <= rotationThreshold && curRotation > rotationThreshold)) {
            OuterEventData eventData = EventConvert.convertStart(drivingData);
            eventData.setEvent(EventType.ignite);
            drivingData.addEventDataToList(eventData);
        }

        var.setPreRotation(curRotation);
        logger.debug("点火算法结束.");
    }

    @Override
    public void collect(OuterStatisticData statisticDataOut) {

    }
}
